package paper.pdf;

class Average {

    int n = 0;
    double sum = 0, sum2 = 0;
    double min, max;

    public Average(double min, double max) {
        this.min = min;
        this.max = max;
    }

    public void addIn(double x) {
        if (x > min && x < max) {
            sum += x;
            sum2 += x*x;
            n++;
        }
    }

    public double mean() {
        return sum/n;
    }

    public double stddev() {
        return Math.sqrt((sum2 - sum * sum/n)/ (n-1));
    }

}